<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="MvcContrib.FluentHtml.ModelViewPage<Universum.Views.QuestionIt.QuestionShowViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Question [
	<%= Model.Question.Title %>
	]
</asp:Content>
<asp:Content ID="BreadcrumbsContent" ContentPlaceHolderID="Breadcrumbs" runat="server">
	<%= Html.Breadcrumb().Home().Append<QuestionItController>(q=>q.Index(0),"Questions").AppendText(Model.Question.Title).End() %>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
	
	<div class="span-22">
		<% Html.RenderPartial("DisplayUC", Model.Question); %>
	</div>
	<div class="span-22">
		<% Html.RenderPartial("QuestionReplyCreateUC", Model.NewReply); %>
	</div>
	<div class="span-22">
		<div class="span-22">
			<% foreach (var item in Model.Replies)
	  { %>
			<% Html.RenderPartial("DisplayReplyUC", item, new ViewDataDictionary().Append( question => Model.Question)); %>
			<% } %>
		</div>
	</div>
	<div id="dialog" title="Remove question?">
		<p>
			<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
			This question will be permanently removed.
			<br />
			Are you sure you want to continue?</p>
	</div>
	<div id="dialog-remove-reply" title="Remove reply?">
		<p>
			<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
			This reply will be permanently removed.
			<br />
			Are you sure you want to continue?</p>
	</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptPlaceHolder" runat="server">
	<% Html.RenderPartial("EditorAndDateUserControl"); %>

	<script type="text/javascript" language="javascript">
		function attach_answer_reply_handlers() {
			$(".mark-reply-answer").click(function() {
				var question_reply = $(this).closest(".question-reply");

				var reply_text = $(".reply-text", question_reply);
				reply_text.removeClass("is-only-reply").addClass("is-answer");
				//$(".marked-offensive-" + parrent_id).html("<small class=\"offensive\"><center>marked offensive</center></small>");

				$(this).removeClass("mark-reply-answer").addClass("unmark-reply-answer");
				$.post($(this).attr("href"),"asdf");
				var attr_href = $(this).attr("href");
				attr_href = attr_href.replace("Mark", "UnMark");
				//alert(attr_href);
				$(this).attr("href", attr_href);
				$(this).unbind("click");
				attach_answer_reply_handlers();
				return false;
			});
			$(".unmark-reply-answer").click(function() {
				var question_reply = $(this).closest(".question-reply");

				var reply_text = $(".reply-text", question_reply);
				reply_text.removeClass("is-answer").addClass("is-only-reply");
				//$(".marked-offensive-" + parrent_id).html("<small class=\"offensive\"><center>marked offensive</center></small>");

				$(this).removeClass("unmark-reply-answer").addClass("mark-reply-answer");
				$.post($(this).attr("href"),"asdf");
				var attr_href = $(this).attr("href");
				attr_href = attr_href.replace("UnMark", "Mark");
				//alert(attr_href);
				$(this).attr("href", attr_href);
				$(this).unbind("click");
				attach_answer_reply_handlers();
				return false;
			});
		}
		function attach_offensive_reply_handlers() {
			$(".mark-reply-offensive").click(function() {
				var question_reply = $(this).closest(".question-reply");
				
				var reply_text = $(".reply-text", question_reply);
				reply_text.addClass("offensive");
				//$(".marked-offensive-" + parrent_id).html("<small class=\"offensive\"><center>marked offensive</center></small>");

				$(this).removeClass("mark-reply-offensive").addClass("unmark-reply-offensive");
				$.post($(this).attr("href"),"asdf");
				var attr_href = $(this).attr("href");
				attr_href = attr_href.replace("Mark", "UnMark");
				//alert(attr_href);
				$(this).attr("href", attr_href);
				$(this).unbind("click");
				attach_offensive_reply_handlers();
				return false;
			});
			$(".unmark-reply-offensive").click(function() {
				var question_reply = $(this).closest(".question-reply");
				var parrent_id = $(this).closest(".question-reply").attr("id");
				var reply_text = $(".reply-text", question_reply);
				reply_text.removeClass("offensive");
				//$(".marked-offensive-" + parrent_id).html("<small class=\"offensive\"><center>marked offensive</center></small>");

				$(this).removeClass("unmark-reply-offensive").addClass("mark-reply-offensive");
				$.post($(this).attr("href"),"asdf");
				var attr_href = $(this).attr("href");
				attr_href = attr_href.replace("UnMark", "Mark");
				//alert(attr_href);
				$(this).attr("href", attr_href);
				$(this).unbind("click");
				attach_offensive_reply_handlers();
				return false;
			});
		}
		function attach_offensive_question_handlers() {
			
		
			$(".offensive-question-link").click(function() {
				var parrent_id = $(this).closest(".question").attr("id");

				$(".marked-offensive-" + parrent_id).html("<small class=\"offensive\"><center>marked offensive</center></small>");
				$(this).removeClass("offensive-question-link").addClass("unoffensive-question-link");
				$.post($(this).attr("href"),"asdf");
				var attr_href = $(this).attr("href");
				attr_href = attr_href.replace("Mark", "UnMark");
				//alert(attr_href);
				$(this).attr("href", attr_href);
				$(this).unbind("click");
				attach_offensive_question_handlers();
				return false;
			});
			$(".unoffensive-question-link").click(function() {
				var parrent_id = $(this).closest(".question").attr("id");
				//alert(parrent_id);
				$(".marked-offensive-" + parrent_id).html("");
				//$.post($(this).attr("href"));
				$(this).removeClass("unoffensive-question-link").addClass("offensive-question-link");
				var attr_href = $(this).attr("href");
				attr_href = attr_href.replace("UnMark", "Mark");
				//alert(attr_href);
				$(this).attr("href", attr_href);
				$(this).unbind("click");
				attach_offensive_question_handlers();
				return false;
			});

		}
		function go_back() {
		var back_url = document.URL;
			var index_of_show = back_url.indexOf("Show");
			back_url = back_url.substring(0, index_of_show);
			window.location.href = back_url + "Index/1";
		}
		$(function() {
			attach_answer_reply_handlers();
			attach_offensive_reply_handlers();
			attach_offensive_question_handlers();
			$(".delete-question-link").click(function() {
				var the_link = $(this);
				var parent_question = $(this).closest("div.question");
				$("#dialog").dialog('option', 'buttons', {
					'Remove this question for real?': function() {
						$.post(the_link.attr("href"),"asdf");

						$(this).dialog('close');
						setTimeout("go_back();", 3000);

					},
					Cancel: function() {
						$(this).dialog('close');
					}
					// buttons
				}); // dialog
				$("#dialog").dialog('open');
				return false;

			}); // delete question link


			$("#dialog").dialog({
				autoOpen: false,
				bgiframe: true,
				resizable: false,
				height: 140,
				width: 400,
				modal: true,
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				}
			}); // dialog
			$("#dialog-remove-reply").dialog({
				autoOpen: false,
				bgiframe: true,
				resizable: false,
				height: 140,
				width: 400,
				modal: true,
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				}
			}); // dialog

		});
</script>
</asp:Content>
